package yawning.mew.cat;

import yawning.mew.sim.SimulationAction;
import yawning.mew.sim.SimulationEventAction;

public class EventSavageRoar extends SimulationEventAction {
	CatModelSimState mState;

	EventSavageRoar(CatModelSimState state) {
		super(state.mSimEngine);
		mState = state;
	}

	@Override
	public double perform() {
		int cps = mState.getComboPoints();
		int cost = mState.getEnergyCost(mState.mModel.srCost);
		if (mState.getEnergy() < cost || cps == 0) return SimulationAction.ACTION_FAIL; // SR is affected by neither Berserk nor OoC.
		int energy = mState.getEnergy();

		// The game will happily let us clip SR with a weaker buff, unlike S&D.
		schedule(mState.mModel.roarInitialDuration + mState.mModel.roarCpBonus * cps);

		if (mState.mIsLogging) mState.mLog.log("Savage Roar: CPs: %d\n", cps);

		mNrSR++;
		mNrSrCPs += cps;
		mState.mBerserkEv.onTier12_4pc_tigger(cps);
		mState.onFinisher();
		mSrEnergy += mState.onEnergyConsumer(cost);

		mState.logResourceChange(energy, cps);

		return 1.0;
	}

	@Override
	public void onExpire() {
		if (mState.mIsLogging) mState.mLog.log("Savage Roar: Expiration\n");
	}

	int mNrSR = 0;
	int mNrSrCPs = 0;

	int mSrEnergy;
}